home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DTP / DTP_TEX / H220.ZIP / ITRNS211.ZIP / SRC / ITOTEX.C < prev    next >
C/C++ Source or Header  |  1991-10-13  |  5KB  |  128 lines

  1. /*
  2.  *========================================================================== 
  3.  * Copyright 1991 Avinash Chopde, All Rights Reserved.
  4.  *
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of Avinash Chopde not be used in
  10.  * advertising or publicity pertaining to distribution of the software
  11.  * without specific, written prior permission.
  12.  * Avinash Chopde makes no representations about the suitability of this
  13.  * software for any purpose.
  14.  * It is provided "as is" without express or implied warranty.
  15.  *
  16.  * AVINASH CHOPDE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  18.  * IN NO EVENT SHALL AVINASH CHOPDE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  20.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  21.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22.  * OF THIS SOFTWARE.
  23.  *
  24.  * Author:  Avinash Chopde, 1991
  25.  *        C2 Colonial Drive #4, Andover, MA 01810, USA.
  26.  *
  27.  */
  28.  
  29. static char S_RCSID[] = "$Header: e:/itrans/src/rcs/itotex.c 1.6 91/10/13 16:51:13 avinash Exp $";
  30.  
  31. #include "itrans.h"
  32.  
  33. /* =================================================================== */
  34. /* define macro names to be used*/
  35. /* name of \newbox to be created */
  36. #define    BOX_NAME    "zErOdEpTh"
  37. /* name of kern macro - \def\..#1{{\kern#1em}} */
  38. #define KERN_NAME    "kRn"
  39. /* name of subscript macro - see macro defn in itotex_start() */
  40. #define SUBS_NAME    "sBs"
  41.  
  42. /* =================================================================== */
  43. static void S_get_texchar(char tchr[], int pcode);
  44. /* =================================================================== */
  45. /****
  46. int cus_to_tex(comp_unit_t* cus, chain of PostScript Chars to output
  47.           int fsize,
  48.           char texcomm[]) the tex commands returned here
  49. *****/
  50. int cus_to_tex(comp_unit_t* cus,
  51.           int fsize,
  52.           char texcomm[])
  53. {
  54.     int dx, dy, pcode;
  55.     char tchr[16];
  56.  
  57.     while (cus) {
  58.     dx = cus->deltax;
  59.     dy = cus->deltay;
  60.     pcode = cus->u_pschar;
  61.  
  62.  
  63. #ifdef DEBUG
  64. fprintf(stderr, "totex: constructing char: dx %d dy %d pcode %d\n", dx, dy, pcode);
  65. #endif /* DEBUG */
  66.  
  67.     if (dx != 0) {
  68.         sprintf(texcomm, "\\%s{%.3f}", KERN_NAME, dx / 1000.0);
  69.         texcomm += strlen(texcomm);
  70.     }
  71.  
  72.  
  73.     if (dy != 0) {
  74.         if (pcode == NO_PSCHAR) {
  75.         
  76.             fprintf(stderr,
  77.         "itotex.c:Error:cus contain an non-zero Ydelta for NO_PSCHAR\n"); 
  78.             /* can't give any more info here, anyway, this error should
  79.              * have been caught when reading in the IFM file....
  80.              * (see font.c::fillup_font())
  81.              */
  82.         } else {
  83.  
  84.             S_get_texchar(tchr, pcode);
  85.             sprintf(texcomm, "\\%s{%.3f}{%s}", SUBS_NAME, dy/1000.0, tchr);
  86.             texcomm += strlen(texcomm);
  87.             /* above macro creates a raised box, but assigns
  88.              * it a height and depth of 0, so that it does
  89.              * change the interline spacing.
  90.              * box name (zERoDeptH) could cause namespace
  91.              * collision with
  92.              * the users text, so use a strange mix...
  93.              */
  94.         }
  95.     } else { /* dy is zero... */
  96.         if (pcode != NO_PSCHAR) {
  97.             S_get_texchar(tchr, pcode);
  98.             sprintf(texcomm, "%s", tchr);
  99.             texcomm += strlen(texcomm);
  100.         }
  101.     }
  102.     
  103.     cus = cus->next;
  104.     } /* while cus */
  105.  
  106.     return TRUE;
  107. }
  108. /* =================================================================== */
  109. static void S_get_texchar(char tchr[], int pcode)
  110. {
  111.     if (isalnum(pcode)) sprintf(tchr, "%c", pcode);
  112.     else if (isprint(pcode)) sprintf(tchr, "{\\char`\\%c}", pcode);
  113.     else sprintf(tchr, "{\\char%d}", pcode);
  114. }
  115. /* =================================================================== */
  116. int outtex_start()
  117. {
  118.     printf("\\newbox\\%s\n", BOX_NAME); /* box used by cus_to_tex()*/
  119.     printf("\\def\\%s#1{{\\kern#1em}}\n", KERN_NAME);
  120.     printf("\\def\\%s#1#2{{\\setbox\\%s=\\hbox{\\raise#1em\\hbox{#2}}%%\n\\ht\\%s=0pt\\dp\\%s=0pt\\box\\%s}}\n",SUBS_NAME,BOX_NAME,BOX_NAME,BOX_NAME,BOX_NAME);
  121.     return TRUE;
  122. }
  123. int outtex_end()
  124. {
  125.     return TRUE;
  126. }
  127. /* ============================^ itotex.c ^ =========================== */
  128.